package main

type unsafeMapx[Key comparable, Value any] map[Key]Value

func newUnsafeMapx[Key comparable, Value any]() unsafeMapx[Key, Value] {
	return make(unsafeMapx[Key, Value])
}
func (m unsafeMapx[Key, Value]) GetKey(key Key) (Value, bool) {
	val, ok := m[key]
	return val, ok
}

func (m unsafeMapx[Key, Value]) Set(key Key, val Value) {
	m[key] = val
}

func (m unsafeMapx[Key, Value]) Delete(key Key) {
	delete(m, key)
}

func (m unsafeMapx[Key, Value]) Len() int {
	return len(m)
}

func (m unsafeMapx[Key, Value]) Range(fn func(Key, Value)) {
	for k, v := range m {
		fn(k, v)
	}
}

func (m unsafeMapx[Key, Value]) Keys() []Key {
	keys := make([]Key, 0, len(m))
	for k := range m {
		keys = append(keys, k)
	}
	return keys
}
